package src.dynamic_programming;

/**
 * @author starsea
 * @date 2024-08-18 13:54
 */

public class bag {
    public static void main(String[] args) {
        int[] arr=new int[]{2};
        int res=coinChange(arr,3);
        System.out.println(res);
    }
    public static int coinChange(int[] coins, int amount) {
        int n=coins.length;
        // 创建dp
        int[][] dp = new int[n + 1][amount + 1];
        //初始化
        for(int j=1;j<=amount;j++)
        {
            dp[0][j]=0x3f3f3f;
        }
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= amount; j++) {
                dp[i][j] = dp[i - 1][j];
                if (j >= coins[i - 1]) {
                    dp[i][j] = Math.min(dp[i-1][j],dp[i][j-coins[i-1]]+1);
                }
            }
        }
        if(dp[n][amount]>=0x3f3f3f){
            return -1;
        }
        return dp[n][amount];
    }
}
